package com.yaoli.niuke;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

/**
 * Created by siemens on 6/2/2017.
 */
public class ComparatorTest {
    public static void main(String[] args) {
        Comparator<P> comparator = new Comparator<P>(){
            @Override
            public int compare(P p1, P p2){
                return p2.zhan - p1.zhan;
            }
        };

        ArrayList<P> list = new ArrayList<>();
        P p = new P();
        p.zhan = 100;
        p.qian = 99;
        list.add(p);
        p = new P();
        p.zhan = 101;
        p.qian = 102;
        list.add(p);
        p = new P();
        p.zhan = 99;
        p.qian = 97;
        list.add(p);

        Collections.sort(list,comparator);

        System.out.print("");
    }
}

class P{
    public int zhan;
    public int qian;
}
